<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
	<!--<![endif]-->
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>个人中心</title>
		<meta name="description" content="">		
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
		<meta content="telephone=no" name="format-detection" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="../styles/font.css"/>
		<link rel="stylesheet" href="../styles/common.css" />
		<link rel="stylesheet" href="../styles/global.css" />
		<link rel="stylesheet" href="../styles/personalCenter.css" />
		<link rel="stylesheet" href="../styles/vant.css"/>
		<!-- 引入组件 -->
		<!-- <script src="../scripts/babel.js" ></script> -->
		<script src="../scripts/babel.js"></script>
		<script src="../scripts/rem.js"></script>
		<script src="../scripts/vue.js"></script>
		<script src="../scripts/api.js"></script>
		<script src="../scripts/axios.js" charset="utf-8"></script>
		<script src="../scripts/vant.js"></script>
		<!-- <script src="//cdn.jsdelivr.net/npm/eruda"></script>
		<script>eruda.init();</script> -->
	</head>
	<body>
		<!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
		<div class="container" id="app">
			<div class="header">
				<div @click="go_back"><span><i class="iconfont icon-back"></i></span></div>
				<div> 我</div>
				<div class="headericon"></div>
			</div>
			<div class="plenl">
				<div class="plenlplenl">
					<div class="headimg">
						<img src="../img/sh.jpg" >
					</div>
					<!--  -->
					<div class="nickname" v-text="admin.cname"></div>
				</div>
				<div class="plenllist" @click="go_index">
					<div >首页</div>
					<div></div>
				</div>
				<div class="plenllist">
					<div @click="go_code">我的二维码</div>
					<div></div> 
				</div>				
				<!--  -->
				
				<div class="plenllist" @click="go_collectionRecord">
					<div >收款记录</div>
					<div></div>
				</div>
				<!-- -->
				<div class="plenllist"  @click="go_statistics">
					<div>收入统计</div>
					<div>

					</div>
				</div>
				<!-- -->
				<div @click="go_fixpassword" class="plenllist">
					<div>修改密码</div>
					<div></div>
				</div>
				<div class="plenllist">
					<div>收款播报</div>
					<div>						
						<van-switch  @input="onInput" v-model="checked" size="18px"/>
					</div>
				</div>
				<!--   -->
				<div @click="logout" class="plenllist">
					<div>退出登录</div>
					<div></div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/babel">
		new Vue({
			el: '#app',
			data: {
				userId:"",
				token:"",
				checked: false,
				url: "",
				tel: "",
				password: "",
				type:"",
				te_checked:"",
				admin:""
			},
			//计算属性			
			mounted: function() {
				debugger
				this.url = url();
				console.log(localStorage.getItem("admin"))
				this.admin = localStorage.getItem("admin")?JSON.parse(localStorage.getItem("admin")):''	;
				if(!this.admin){
					this.$notify("非法登录，请重新登陆");
					setTimeout(this.go_login,2000);	
				}
				this.userId = this.admin.mid;
				this.token = this.admin.token;
				this.type = this.admin.type;
				if(this.type==1){
					this.checked=true
				}else{
					this.checked=false
				}
			},
			
			methods: {
				// 收款播报 选择
				onInput(checked) {
					var that =this;	
					if(checked){
						that.$dialog.confirm({
							title: '提醒',
							message: '是否打开播报开关？'
						}).then(() => {
							console.log(that.checked)
							that.checked = checked;
							that.updateMchIsBroadcast(1);
						}).catch(() => {						
							that.checked = !checked;
						});
						
					}else{
						that.$dialog.confirm({
							title: '提醒',
							message: '是否关闭播报开关'
						}).then(() => {
							that.checked = checked;
							that.updateMchIsBroadcast(2);
						}).catch(() => {
							
							that.checked =!checked;
						});
					}					
				},
				// 确认开启或者关闭 掉接口/mchapp/info/updateMchIsBroadcast
				updateMchIsBroadcast:function(num){
					var that = this;					
					var data = {
						userId: that.userId,
						token: that.token,
						requestString: JSON.stringify({
							mid: that.userId,
							type:num
						})
					};
					console.log(data)
					axios.post(that.url + '/mchapp/info/updateMchIsBroadcast', data).then(function(response) {
						
							console.log(response.data);
							if (response.data.code == 200) {								
								that.$notify("修改成功");
								if(that.checked ==true){
									that.admin.type =1; 
								}else{
									that.admin.type =2; 
								}
								localStorage.setItem("admin",JSON.stringify(that.admin) );								
							} //判断单点登录
							else if(response.data.code == 300){
								that.$notify("账号在别处登录，将为您返回登录页面");//							
								if(that.admin.teltype==1){
									logout_app(that.admin.mid,1)
								}
								if(that.admin.teltype==2){
									logout_app(that.admin.mid,2)
								}	
								window.location.href ='../login.html';
							} else {
								that.te_checked = '';
								that.$notify(response.data.disp);
								localStorage.removeItem('admin');
								window.location.href = "../login.html"
							}
						})
				},				
				go_back: function() {
					window.history.back(-1); 
				},
				go_index: function() {
					window.location.href = '../index.html';
				},
				go_collectionRecord: function() {
					window.location.href = 'collectionRecord.html';
				},
				go_statistics: function() {
					window.location.href = 'statistics.html';
				},
				go_fixpassword: function() {
					window.location.href = '../fixpassword.html';
				},
				go_login:function(){
					window.location.href = '../login.html';
				},
				go_code:function(){					
					window.location.href = 'my_code.html';
				},
				logout:function(){
					var that = this;
					that.$dialog.confirm({
						title: '提醒',
						message: '是否退出登录'
					}).then(() => {	
						window.location.href = '../login.html';
						localStorage.removeItem('admin');
						if(that.admin.teltype==1){
							logout_app(that.admin.mid,1)
						}
						if(that.admin.teltype==2){
							logout_app(that.admin.mid,2)
						}
						
					}).catch(() => {							
							
					});
				}
			}

		})
	</script>
</html>
